package com.fly.monitor.console.aspect;

import com.fly.monitor.core.helper.MDCHelper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ReportLogAspect {

    private static final Logger log = LoggerFactory.getLogger(ReportLogAspect.class);

    @Pointcut("execution(* com.fly.monitor.console.controller..*.*(..))")
    public void pointCut() {
    }

    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        String traceId = MDCHelper.init();
        log.info("ReportLogAspect around report some log traceId -> {}", traceId);
        return point.proceed();
    }

    @After(value = "pointCut()")
    public void after() throws Throwable {
        MDCHelper.clear();
    }
}